/*
 * Copyright (c) 1998, 1999 Henry Spencer.  All rights reserved.
 *
 * Development of this software was funded, in part, by Cray Research Inc.,
 * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
 * Corporation, none of whom are responsible for the results.  The author
 * thanks all of them.
 *
 * Redistribution and use in source and binary forms -- with or without
 * modification -- are permitted for any purpose, provided that
 * redistributions in source form retain this entire copyright notice and
 * indicate the origin and nature of any modifications.
 *
 * I'd appreciate being given credit for this package in the documentation
 * of software which uses it, but that is not a requirement.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * src/include/regex/regcustom.h
 */

/* 头文件（如果有的话） */

/*
 * 在头文件中包含postgres.h违反了Postgres的编码规范，
 * 但我们在这里允许这一违规，因为正则库文件特别
 * 旨在使此文件提供依赖于应用程序的头文件，
 * 并且在包含其他任何内容之前小心地包含此文件。
 */
#include "postgres.h"

#include <ctype.h>
#include <limits.h>

/*
 * towlower()及其他函数应在<wctype.h>中，但某些C99之前的系统
 * 在<wchar.h>中声明它们，因此也包括该头文件。
 */
#include <wchar.h>
#ifdef HAVE_WCTYPE_H
#include <wctype.h>
#endif

#include "mb/pg_wchar.h"

#include "miscadmin.h"			/* 需要由rcancelrequested/rstacktoodeep */


/* 对regguts.h定义的覆盖（如果有的话） */
#define FUNCPTR(name, args) (*name) args
#define MALLOC(n)		malloc(n)
#define FREE(p)			free(VS(p))
#define REALLOC(p,n)	realloc(VS(p),n)
#define assert(x)		Assert(x)

/* 内部字符类型及相关 */
typedef pg_wchar chr;			/* 类型本身 */
typedef unsigned uchr;			/* 无符号类型，将保存一个chr */

#define CHR(c)	((unsigned char) (c))	/* 将字符字面量转换为chr字面量 */
#define DIGITVAL(c) ((c)-'0')	/* 将chr数字转换为其值 */
#define CHRBITS 32				/* chr中的位；不得使用sizeof */
#define CHR_MIN 0x00000000		/* 最小和最大chr；值 */
#define CHR_MAX 0x7ffffffe		/* CHR_MAX-CHR_MIN+1必须适合int，并且
								 * CHR_MAX+1必须适合chr变量 */

/*
 * 检查chr值是否在范围内。理想情况下我们可以简单地写为
 *		((c) >= CHR_MIN && (c) <= CHR_MAX)
 * 然而，如果chr是无符号的并且CHR_MIN是零，那么
 * 这部分是无操作的，而且某些过于严格的编译器会对此发出警告。
 * 所以我们在这里省略掉。如果你想让chr有符号和/或
 * CHR_MIN不为零，请如上所述重新定义此宏。
 * 调用者应该假定该宏可能会多次评估其参数，
 * 即使今天没有。
 */
#define CHR_IS_IN_RANGE(c)	((c) <= CHR_MAX)

/*
 * MAX_SIMPLE_CHR是“简单”和“复杂”处理之间的界限
 * 在颜色映射逻辑中。它通常应该选择足够高，以确保
 * 所有常见字符都<= MAX_SIMPLE_CHR。然而，非常大的
 * 值会适得其反，因为它们会导致更多的正则表达式设置时间。
 * 此外，小值对于测试高色彩图逻辑
 * 配合普通ASCII输入可能是有帮助的。
 */
#define MAX_SIMPLE_CHR	0x7FF	/* 适合Unicode的值 */

/* 操作chr的函数 */
#define iscalnum(x) pg_wc_isalnum(x)
#define iscalpha(x) pg_wc_isalpha(x)
#define iscdigit(x) pg_wc_isdigit(x)
#define iscspace(x) pg_wc_isspace(x)

/* 并获取标准头文件 */
#include "regex.h"
